/*
 * Copyright (c) 2025-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_HIVIEWDFX_XPERFSERVICECLIENT_H
#define OHOS_HIVIEWDFX_XPERFSERVICECLIENT_H

#include <cstring>
#include <vector>
#include <iremote_object.h>
#include "ixperf_service.h"

namespace OHOS {
namespace HiviewDFX {
class XperfServiceClient {
public:

    static XperfServiceClient& GetInstance();

    void ResetClient();

    void NotifyToXperf(int32_t domainId, int32_t eventId, const std::string& msg);

    int32_t RegisterVideoJank(const std::string& caller, const sptr<IVideoJankCallback>& cb);

    int32_t UnregisterVideoJank(const std::string& caller);

    int32_t RegisterAudioJank(const std::string& caller, const sptr<IAudioJankCallback>& cb);

    int32_t UnregisterAudioJank(const std::string& caller);

private:
    XperfServiceClient();
    ~XperfServiceClient();

private:
    bool CheckClientValid();

private:
    class XPerfServiceDeathRecipient : public IRemoteObject::DeathRecipient {
    public:
        explicit XPerfServiceDeathRecipient(XperfServiceClient &client);

        ~XPerfServiceDeathRecipient();

        void OnRemoteDied(const wptr<IRemoteObject> &object) override;

    private:
        XperfServiceClient& xperfServiceClient;
    };

private:
    std::mutex mutex;
    sptr<XPerfServiceDeathRecipient> recipient;
    static constexpr HiLogLabel LABEL = {LOG_CORE, 0xD002D66, "XPERF_SERVICE"};
};
} // namespace HiviewDFX
} // namespace OHOS

#endif
